#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
 
int
main(int argc, char **argv)
{
   int opt;
   int digit_optind = 0;
   int option_index = 0;
   char *optstring = "a:b:c:d";
   static struct option long_options[] = {
       {"reqarg", required_argument, NULL, 'r'},
       {"noarg",  no_argument,       NULL, 'n'},
/*       {"optarg", optional_argument, NULL, 'o'},*/
       {"optarg", required_argument, NULL, 'o'},
       {0, 0, 0, 0}
   };
 
   option_index = -1;
   while ( (opt = getopt_long(argc, argv, optstring, long_options, &option_index)) != -1)
   {
/*        printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");*/
/*        printf("opt = %c\n", opt);*/
/*        printf("optarg = %s\n", optarg);*/
/*        printf("optind = %d\n", optind);*/
/*        printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");*/
        
        if( option_index >= 0 ){
            printf("option_index = %d\n", option_index);
            printf("long_options[option_index] = %s\n", long_options[option_index].name);
/*            printf("optind = %d\n", optind);*/
            printf("option_value = %s\n\n", optarg);
/*            printf("argv[optind - 1] = %s\n\n",  argv[optind - 1]);*/
            
            option_index = -1;
        }
   }
 
   return 0;
}
